﻿using System.Windows.Forms;
using System.Drawing;
using System;

namespace BS.FormControls
{
    public class SearchTextBox : TextBox
    {
        private string _filterText = "please enter your search text.";
        public string FilterText
        {
            internal get { return _filterText; }
            set { _filterText = value; }
        }

        public SearchTextBox()
        {
            Text = FilterText;
            Font = new Font(Font, FontStyle.Italic);
        }

        //protected override void OnGotFocus(System.EventArgs e)
        //{
        //    if (this.Text == this.FilterText)
        //        this.Text = String.Empty;
        //    base.OnGotFocus(e);
        //}

        //protected override void OnLostFocus(EventArgs e)
        //{
        //    if (string.IsNullOrEmpty(this.Text))
        //        this.Text = this.FilterText;
        //    base.OnLostFocus(e);
        //}

        protected override void OnTextChanged(System.EventArgs e)
        {
            if (!String.IsNullOrEmpty(Text) && this.Text != this.FilterText)
                base.OnTextChanged(e);
        }

        protected override void OnEnter(EventArgs e)
        {
            if (this.Text == this.FilterText)
                this.Text = String.Empty;
            base.OnEnter(e);
        }

        protected override void OnLeave(EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Text))
                this.Text = this.FilterText;
            base.OnLeave(e);
        }
    }
}
